<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备品类" prop="deviceCategory">
        <el-select @change="getDeviceList()"
          v-model="queryParams.deviceCategory"
          placeholder="请选择设备品类"
          class="form-item"
          clearable
          filterable
        >
          <el-option
            v-for="item in dict.type.device_category"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="设备SN" prop="deviceNo">
        <el-input
          v-model="queryParams.deviceNo"
          placeholder="请输入设备SN"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-if="queryParams.deviceCategory === '1'" :data="dataDeviceList"
              border size="mini" style="width: 100%">
      <el-table-column prop="sn" label="SN" width="300"></el-table-column>
      <el-table-column prop="hm" label="主机"></el-table-column>
      <el-table-column prop="time" label="时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="ps" label="数据"></el-table-column>
    </el-table>
    <el-table v-if="queryParams.deviceCategory === '0'"
              :data="dataDeviceList" border size="mini" style="width: 100%">
      <el-table-column prop="sn" label="SN" width="300"></el-table-column>
      <el-table-column prop="time" label="时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="waterDeviceMessages" label=数据>
        <template slot-scope="scope">
          <div v-for="item in scope.row.waterDeviceMessages">
            <span>{{ item.device }} - {{item.field1}}- {{ item.field2 }}- {{item.field3}}- {{ item.field4 }}- {{ item.field5 }}- {{ item.field6}}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="csq" label="信号"></el-table-column>
      <el-table-column prop="vat" label="电压"></el-table-column>
      <el-table-column prop="imei" label="物联网卡号"></el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listFloor, getFloor, delFloor, addFloor, updateFloor, floorPush, delFloorId} from "@/api/system/floor"
import {gatewayUplinkData, waterUplinkData} from "@/api/system/device";
import {parseTime} from "../../../utils/ruoyi";

export default {
  name: "dataDevice",
  dicts: ['device_category'],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      dataDeviceList: [],//设备数据
    }
  },
  created() {
    // this.getList()
  },
  methods: {
    parseTime,
    /** 查询楼层信息列表 */
    getList() {
      this.loading = true
      const query = {
        pageNum: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize,
        deviceNo: this.queryParams.deviceNo.trim(),
      }
      if (this.queryParams.deviceCategory === '1') {
        gatewayUplinkData(query).then(response => {
          this.dataDeviceList = response?.data?.records
          this.deviceDataTotal = response?.total
        })
        this.loading = false

      } else {
        waterUplinkData(query).then(response => {
          this.dataDeviceList = response?.data?.records
          this.deviceDataTotal = response?.total
        })
        this.loading = false
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.dataDeviceList =  []
    },
    /** 清空表格 */
    getDeviceList() {
      this.dataDeviceList =  []
    },
  }
}
</script>
<style>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>
